#ifndef _TW8835_H_
#define	_TW8835_H_

//#define OSD_PAGE			0x07  //pls remove

//==<<PAGE & TWBASE>>=================================================
#define PAGE0_GENERAL		0x00
#define PAGE0_OUTPUT		0x00	//0x007::0x00F & 0x01F
#define PAGE0_INPUT			0x00	//0x040::0x046
#define PAGE0_BT656			0x00	//0x047::0x04A
#define PAGE0_DTV			0x00	//0x050::0x05F
#define PAGE0_GPIO			0x00	//0x080::0x09E
#define PAGE0_MBIST			0x00	//0x0A0::0x0A4
#define PAGE0_TOUCH			0x00	//0x0B0::0x0B4
#define PAGE0_LOPOR			0x00	//0x0D4::0x0DF
#define PAGE0_LEDC			0x00	//0x0E0::0x0E6
#define PAGE0_DCDC			0x00	//0x0E8::0x0EC
#define PAGE0_VCOM			0x00	//0x0ED::0x0EE
#define PAGE0_SSPLL			0x00	//0x0F6::0x0FD
#define TW88_FPLL0			0xF8
#define TW88_FPLL1			0xF9
#define TW88_FPLL2			0xFA
#define TW88_SSPLL_ANALOG	0xFD
#define PAGE1_DECODER		0x01	//0x101::0x142
#define PAGE1_VADC			0x01	//0x1C0::0x1E7	include LLPLL
#define PAGE1_LLPLL			0x01	//0x1C0::0x1E7	include LLPLL
#define PAGE2_SCALER		0x02	//0x201::0x21E
#define PAGE2_TCON			0x02	//0x240::0x24E
#define PAGE2_IMAGE			0x02	//0x280::0x2BF
#define PAGE2_GAMMA			0x02	//0x2E0::0x2E3 include LCDC
#define PAGE2_DITHER		0x02	//0x2E4::0x2E4
#define PAGE2_RGBLEVEL		0x02	//0x2F0::0x2F5
#define PAGE2_8BITPANEL		0x02	//0x2F8::0x2F9
#define PAGE3_FOSD			0x03	//0x300::0x354
#define PAGE4_SOSD			0x04	//0x400::0x3BE
#define PAGE4_SPI			0x04	//0x4C0::0x4DA include MCU
#define TWBASE_SPI			0xC0	//note:Not a page. it is a offset.
#define PAGE4_CLOCK			0x04	//0x4E0::0x4EB
#define PAGE5_MEAS			0x05	//0x500::0x545


#define WriteTW88Page(b)	regTW88[(BYTE)0xff] = ((BYTE)(b))

#define WriteTW88(a, b)		regTW88[(BYTE)(a)] = ((BYTE)(b))
#define	ReadTW88(a)			regTW88[(BYTE)(a)]
#define TW88Write(a, b)		regTW88[(a)] = ((BYTE)(b))
#define TW88Read(a, b)		regTW88[(a)] = ((BYTE)(b))


#if 0
inline void TW88Reg16WriteMask(BYTE rhi, BYTE rlo, WORD value, BYTE rmask, BYTE vmask, BYTE vshift)
{
	WriteTW88(rhi, (ReadTW88(rhi) & ^rmask) | ((value & (vmask<<8)) >> vshift));
	WriteTW88(rlo, (BYTE)value);
}
#else
#define TW88Reg16WriteMask(rhi, rlo, value, rmask, vmask, vshift) \
	WriteTW88(rhi, (ReadTW88(rhi) & ^rmask) | ((value & (vmask<<8)) >> vshift)); \
	WriteTW88(rlo, (BYTE)value)
#endif
#define TW88Reg16Write(rhi,rlo,value) WriteTW88(rhi, (value >> 8)); WriteTW88(rlo, (BYTE)value)
#define Write2TW88(rhi,rlo,value) WriteTW88(rhi, (value >> 8)); WriteTW88(rlo, (BYTE)value)
#define Read2TW88(rhi,rlo,value) value=ReadTW88(rhi); value <<= 8; value |= ReadTW88(rlo)
#define Read3TW88(rhi,rmid,rlo,value) value=ReadTW88(rhi); value <<= 8; value |= ReadTW88(rmid); value <<= 8; value |= ReadTW88(rlo)


#endif	//.._TW8835_H_




